<html>
<head><meta charset="utf-8"><title>fpenv · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html">fpenv</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178454083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454083">(Oct 18 2019 at 08:34)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I'm not sure I understand why modifying fpenv isn't an error in the abstract machine</p>



<a name="178454106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454106">(Oct 18 2019 at 08:35)</a>:</h4>
<p>IIUC from your latest comment, the idea is that there is no fpenv in the abstract machine, so reading it or modifying it is not something that we can talk about at that level</p>



<a name="178454172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454172">(Oct 18 2019 at 08:36)</a>:</h4>
<p>But OTOH Rust assumes that floating point math behaves in a certain way</p>



<a name="178454262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454262">(Oct 18 2019 at 08:38)</a>:</h4>
<p>And one can configure the hardware to not behave in that way</p>



<a name="178454268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454268">(Oct 18 2019 at 08:38)</a>:</h4>
<p>So I see this as a similar thing to "target-feature"</p>



<a name="178454296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454296">(Oct 18 2019 at 08:39)</a>:</h4>
<p>That is, this is UB of the form of running the binary produced on hardware that does not support it</p>



<a name="178454298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454298">(Oct 18 2019 at 08:39)</a>:</h4>
<p>Not that much different from trying to run an arm binary on x86</p>



<a name="178454354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454354">(Oct 18 2019 at 08:40)</a>:</h4>
<p>I don't know what the right level is to talk about this kind of UB</p>



<a name="178454455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454455">(Oct 18 2019 at 08:42)</a>:</h4>
<p>With the proposed definition, this is not an error in the abstract machine, but an user error maybe ?</p>



<a name="178454538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454538">(Oct 18 2019 at 08:43)</a>:</h4>
<p>That is, when you tell your compiler to compile a program for x86, the abstract machine promises that, if that program has no UB, it will produce a program that runs on x86 with the same semantics</p>



<a name="178454591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454591">(Oct 18 2019 at 08:44)</a>:</h4>
<p>If the user then goes and takes that program and runs it on something else, well, that's an error, but it is not an error in the abstract machine per se</p>



<a name="178454598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454598">(Oct 18 2019 at 08:44)</a>:</h4>
<p>It is however something for which we do not provide any guarantees, and therefore a different form of UB</p>



<a name="178454701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454701">(Oct 18 2019 at 08:46)</a>:</h4>
<p>This kinds of match what's mentioned in <a href="https://github.com/rust-lang/miri/issues/932#issuecomment-541567466" target="_blank" title="https://github.com/rust-lang/miri/issues/932#issuecomment-541567466">https://github.com/rust-lang/miri/issues/932#issuecomment-541567466</a></p>



<a name="178454737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178454737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178454737">(Oct 18 2019 at 08:47)</a>:</h4>
<p>Which makes UB due to incorrect usage of target-features an error on the "miri CPU", not the rust abstract machine.</p>



<a name="178536816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178536816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178536816">(Oct 19 2019 at 08:59)</a>:</h4>
<blockquote>
<p>IIUC from your latest comment, the idea is that there is no fpenv in the abstract machine, so reading it or modifying it is not something that we can talk about at that level</p>
</blockquote>
<p>exactly</p>



<a name="178536817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv/near/178536817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/fpenv.html#178536817">(Oct 19 2019 at 08:59)</a>:</h4>
<p>I think we came to agreement in <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/202#issuecomment-543604668" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/202#issuecomment-543604668">https://github.com/rust-lang/unsafe-code-guidelines/issues/202#issuecomment-543604668</a> ?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>